
<?php
/**
 * Created by PhpStorm.
 * User: sunshine
 * Date: 2016/8/31
 * Time: 8:40
 */
require_once "Admin/Controller/Controller.php";
require_once "Admin/Model/B_testModel.php";

class B_testController extends Controller
{function __Construct(){
    parent::__Construct();
$this->model=new B_testModel();
}

    function testlist(){
        if (isset($_SESSION['admin'])) {
            $model = new B_testModel();
            $data = $model->getTestList();
            $this->assign('test', $data);
            $this->display();
        }
    }
    function form(){
        if (isset($_SESSION['admin']))
        $this->display();
    }
    function add(){
        if (isset($_SESSION['admin'])){
        $data=$_POST;
       // var_dump($data);
        $model = new B_testModel();
        $result = $model->addTest($data);
       if($result){
            echo '添加成功 <a href="admin.php?c=b_test&m=testlist">如果没有跳转，请点这里跳转</a>';
           
        }
        else{
            echo "添加失败！<br/>";
            
        }
    }
    }
    function mod()
    {
        if (isset($_SESSION['admin']))
        {
        $id = $_GET['id'];

        $result = $this->model->getTestByID($id);
        $this->assign('test',$result);
        $this->display(); 
    }
    }
    function update()
    {
        if (isset($_SESSION['admin'])) 
        {
            $data = $_POST;
            
            $result = $this->model->update($data);
            if ($result) 
            {
                echo '更新成功 <a href="admin.php?c=b_test&m=testlist">如果没有跳转，请点这里跳转</a>';
               header("refresh:3;url='admin.php?c=b_test&m=testlist'");
            } else 
            {
                echo "更新失败！<br/>";
                echo "<a href='admin.php?c=b_test&m=mod&id=" . $data['id'] . "'>返回</a>";
            }
        }
    }
    function del(){
        $id = $_GET['id'];
        $model = new B_testModel();
        $result = $model->delTest($id);
        if($result){
            echo '删除成功 <a href="admin.php?c=b_test&m=testlist">如果没有跳转，请点这里跳转</a>';
            
        }
        else{
            echo "删除失败！<br/>";
            echo "<a href='admin.php?c=b_test&m=testlist'>返回</a>";
        }
    }
}
?>
